package cn.longg.service.impl;

import cn.longg.entity.Dept;
import cn.longg.entity.User;
import cn.longg.mapper.DeptMapper;
import cn.longg.mapper.UserMapper;
import cn.longg.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DeptServieImpl extends BaseServiceImpl<Dept> implements IDeptService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> selectAll() {
        List<Dept> depts = super.selectAll();
        for (Dept dept : depts) {
            List<User> userList = userMapper.selectByDeptId(dept.getId());
            dept.setUserList(userList);
        }
        return depts;
    }
}
